<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>后台管理</title>
{{include file="layouts/_head"}}
</head>
<body>
<div class="main">
	<ol class="breadcrumb">
        <li><i class="icon_home iconfont"></i>首页</li>
	  	<li>版块管理</li>
	  	<li><a href="javascript:history.go(-1);">版块列表</a></li>
	  	<li class="active">编辑版块</li>
	</ol>
	<div class="bg-danger clearfix main-head-info error-info"></div>
	<div class="main-con">
		<ul class="nav nav-tabs" id="tabs">
		  	<li class="active"><a href="javascript:void(0)" data-id="#general">基础信息</a></li>
		  	<li><a href="javascript:void(0)" data-id="#values">版块产品</a></li>
		</ul>
		<form class="form-horizontal margin-t-30" id="form" method="post" action="{{:url('/admin/section/update')}}">
        <input type="hidden" name="id" value="{{$section.id}}">
		  	<div class="tab-box" id="general">
          <div class="form-group">
              <span class="col-sm-2 control-label"><i class="iconfont iconfont-question" data-toggle="tooltip" data-placement="top" data-original-title="客户端使用设备"></i> <span class="color-red">*</span> 设备：</span>
              <div class="col-sm-2 input-group">
              <select class="form-control" name="client">
                  <option value="">请选择</option>
                  {{volist name="clientArray" id="vo"}}
                  <option value="{{$key}}" {{if $key == $section.client}} selected {{/if}}>{{$vo}}</option>
                  {{/volist}}
              </select>
              </div>
          </div>
			  	<div class="form-group">
			    	<span class="col-sm-2 control-label"><span class="color-red">*</span> 版块名：</span>
			    	<div class="col-sm-8 input-group">
			    		<input class="form-control" name="name" value="{{$section.name}}">
			    	</div>
			  	</div>
			  	<div class="form-group">
				    <span class="col-sm-2 control-label">简要描述：</span>
				    <div class="col-sm-8 input-group">
				     	<textarea class="form-control" rows="3" name="description">{{$section.description}}</textarea>
				    </div>
			  	</div>
			</div>
			<div class="tab-box clearfix" id="values">
                <div class="main-head">
                    <select class="form-control width-150 pull-left" id="cl_category_id">
                        <option value="">全部分类</option>
                        {{volist name="$categorys" key="key" id="vo"}}
                        {{if $Request.param.category_id eq $vo.id}}
                        <option selected="true" value="{{$vo.id}}">{{php}}for($i=1; $i<$vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                        {{else}}
                        <option value="{{$vo.id}}">{{php}}for($i=1; $i<$vo['level']; $i++) {echo '&nbsp;&nbsp;&nbsp;&nbsp;';}{{/php}}{{$vo.name}}</option>
                        {{/if}}
                        {{/volist}}
                    </select>
                    <input type="text" class="form-control width-150 margin-l-5 pull-left" id="cl_product_name" value="{{$Request.param.keyword}}" placeholder="产品名" >
                    <a type="submit" class="btn btn-primary margin-l-5" onclick="getProducts()">搜索</a>
                </div>
                <table class="table table-bordered" id="checkAll">
                  <thead>
                    <tr>
                      <th style="width: 50px;"><input type="checkbox" id="checkAll_click" autocomplete="off"></th>
                      <th style="width: 50px;">ID</th>
                      <th>产品名</th>
                      <th>分类</th>
                      <th>品牌</th>
                      <th>状态</th>
                    </tr>
                  </thead>
                  <tbody id="correlation-box">
                    {{if $section.values}}
                      {{volist name="$section.values" id="vo"}}
                      <input type="hidden" name="haveProductIds[]" value="{{$vo.id}}">
                      <tr>
                          <td><input type="checkbox" name="productIds[]" value="{{$vo.id}}" checked="true"></td>
                          <td>{{$vo.id}}</td>
                          <td>{{$vo.name}}</td>
                          <td>{{$vo.full_category_name}}</td>
                          <td>{{$vo.brand_name ? $vo.brand_name : '无'}}</td>
                          <td>
                            {{if $vo.status == 1}}<span class="label label-success">上架</span>{{else}}<span class="label label-danger radius">下架</span>{{/if}}
                          </td>
                      </tr>
                      {{/volist}}
                      {{else}}
                      <tr id="correlation-box-message">
                        <td colspan="6">请进行搜索！</td>
                      </tr>
                      {{/if}}
                  </tbody>
                </table>        
			</div>
			<div class="form-group" >
				<div class="col-sm-offset-2 col-sm-1">
				  <button type="submit" class="btn btn-primary">提交</button>
				</div>
			</div>
		</form>
	</div>
</div>
{{include file="layouts/_foot"}}
{{include file="shared/_jquery_validation"}}
<script type="text/javascript" src="/static/admin/plugins/luck.file.upload.js"></script>
<script type="text/javascript" src="/static/admin/script/section.js"></script>
<script type="text/javascript">
$("#form").validate({
    rules: {
        name: {required: true},
    },
    messages: {
        name: '版块名不能为空',
    },
    submitHandler:function(){
        layer.confirm('确认提交？', {
            btn: ['确认','取消']
        }, function(){
            var load = layer.load();
            $("#form").ajaxSubmit(function(data) {
                layer.close(load);
                if (data.code == 401) {
                    goLogin('admin');
                } else if (data.code == 200) {
                    layer.msg('提交成功', {time: 1500}, function() {window.location.href = '{{:url("/admin/section")}}'});
                } else if (data.code == 400) {
                    layer.msg(data.message);
                } else {
                    layer.msg('操作失败');
                }
            });
        }); 
    },
    invalidHandler: function(form, validator) {
         goTop();
    }
});
</script>
</body>
</html>